package ${packageName}.${moduleName}.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ${packageName}.${moduleName}.dao.${capitalizeName}Mapper;
import ${packageName}.${moduleName}.service.${capitalizeName}Service;
import ${packageName}.${moduleName}.model.${capitalizeName};
import ${packageName}.${moduleName}.model.ServiceResult;
import ${packageName}.${moduleName}.model.ResultCode;

/**
 * ${functionName}
 * @author ${author}
 * @date ${date}
 */
@Service("${uncapitalizeName}Service")
public class ${capitalizeName}ServiceImpl implements ${capitalizeName}Service{
	
	@Autowired
	private ${capitalizeName}Mapper ${uncapitalizeName}Mapper;
	
	@Override
	public ServiceResult<${capitalizeName}> get${capitalizeName}(int id) {
		${capitalizeName} ${uncapitalizeName}= ${uncapitalizeName}Mapper.selectByPrimaryKey(id);
		return new ServiceResult<${capitalizeName}>(ResultCode.success,${uncapitalizeName});
	}

	@Override
	public ServiceResult<String> update${capitalizeName}(${capitalizeName} ${uncapitalizeName}) {
		int code=${uncapitalizeName}Mapper.updateByPrimaryKeySelective(${uncapitalizeName});
		if(code==1) {
			return new ServiceResult<String>(ResultCode.success,"");
		}
		return new ServiceResult<String>(ResultCode.updateError,ResultCode.updateErrorMsg);
	}

	@Override
	public ServiceResult<String> add${capitalizeName}(${capitalizeName} ${uncapitalizeName}) {
		int code=${uncapitalizeName}Mapper.insert(${uncapitalizeName});
		if(code==1) {
			return new ServiceResult<String>(ResultCode.success,"");
		}
		return new ServiceResult<String>(ResultCode.addError,ResultCode.addErrorMsg);
	}

	@Override
	public ServiceResult<String> delete${capitalizeName}(int hostId) {
		int code=${uncapitalizeName}Mapper.deleteByPrimaryKey(hostId);
		if(code==1) {
			return new ServiceResult<String>(ResultCode.success,"");
		}
		return new ServiceResult<String>(ResultCode.deleteError,ResultCode.deleteErrorMsg);
	}
}
